/*
 * Created on 13/Dez/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package libjdc.dc.client;

import hubsniffer.*;
import hubsniffer.conn.HubConnection;

/**
 * @author Daniel Botelho
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class User{
	
	private static final int DEFAULT_PORT = -1;
	private static final String DEFAULT_HOST = "";
        
        private HubConnection hubConnection;
	
	private UserInfo userInfo;

	//private String ip = this.getHost()+":"+this.getPort();
	private String host = DEFAULT_HOST;
	private int port = DEFAULT_PORT;
	
	public void setIp(String ip){
            if(ip.indexOf(':')>0){
                this.setHost(ip.substring(0,ip.indexOf(':')));
                this.setPort(new Integer(ip.substring(ip.indexOf(':')+1)).intValue());
            }else
                this.setHost(ip);
        }
	
	/**
	 * @return Returns the host.
	 */
	public String getHost() {
		return host;
	}
	/**
	 * @param host The host to set.
	 */
	public void setHost(String host) {
		this.host = host;
	}
	/**
	 * @return Returns the port.
	 */
	public int getPort() {
		return port;
	}
	/**
	 * @param port The port to set.
	 */
	public void setPort(int port) {
		this.port = port;
	}

        public User(boolean isOp,String nick,String description,String speed,String email,long sharedBytes, String passwd){
		userInfo = new UserInfo(this);
		userInfo.setNick(nick);
		userInfo.setDescription(description);
		userInfo.setSpeed(speed);
		userInfo.setEmail(email);
		userInfo.setSharedBytes(sharedBytes);
                userInfo.setPasswd(passwd);
                userInfo.setOp(isOp);
	}
        
	public User(String nick,String description,String speed,String email,long sharedBytes){
		this(false,nick,description,speed,email,sharedBytes,null);
	}
        
        public User(String nick){
		this(false,nick,"","","",0,null);
	}
        
        public User(boolean isOp,String nick){
		this(isOp,nick,"","","",0,null);
	}
        
	/**
	 * @return Returns the userInfo.
	 */
	public UserInfo getUserInfo() {
		return userInfo;
	}
	/**
	 * @param userInfo The userInfo to set.
	 */
	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}
	public String toString(){
            return host+":"+port+" - UserInfo: "+userInfo.toString();
        }

    public String getIp() {
        return getHost();
    }

    public HubConnection getHubConnection() {
        return hubConnection;
    }

    public void setHubConnection(HubConnection hubConnection) {
        this.hubConnection = hubConnection;
    }

}
